package edu.scau.mis.web.controller;

import edu.scau.mis.pos.entity.PosItem;
import edu.scau.mis.pos.entity.PosOrder;
import edu.scau.mis.pos.service.IPosOrderService;
import edu.scau.mis.pos.vo.OrderItemVo;
import edu.scau.mis.pos.vo.OrderVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Generated;
import javax.annotation.Resource;
import javax.xml.ws.Action;
import java.util.List;
/**
 * 订单表(PosOrder)表控制层
 *
 * @author CJW
 * @since 2021-11-08 21:23:50
 */
@RestController
@RequestMapping("posOrder")
public class PosOrderController {
    /**
     * 服务对象
     */
    @Resource
    private IPosOrderService iPosOrderService;

    /**
     * 分页查询
     *
     * @param posOrder 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<PosOrder>> queryAll(PosOrder posOrder) {
        return ResponseEntity.ok(this.iPosOrderService.queryAll(posOrder));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<PosOrder> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.iPosOrderService.queryById(id));
    }

//    /**
//     * 新增数据
//     *
//     * @param posOrder 实体
//     * @return 新增结果
//     */
//    @PostMapping
//    public ResponseEntity<PosOrder> add(@RequestBody PosOrder posOrder) {
//        return ResponseEntity.ok(this.iPosOrderService.insert(posOrder));
//    }

    /**
     * 编辑数据
     *
     * @param posOrder 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<PosOrder> edit(@RequestBody PosOrder posOrder) {
        return ResponseEntity.ok(this.iPosOrderService.update(posOrder));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.iPosOrderService.deleteById(id));
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, PosOrder posOrder) {
        PageHelper.startPage(pageNum,pageSize);
        List<PosOrder> list = this.iPosOrderService.queryAll(posOrder);
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }

    /**
     * 步骤2:输入待借读者-图书
     *
     * @param
     * @return 新增结果
     */
//    @PostMapping ("/addOrder")
//    public ResponseEntity<PosOrder> addOrder(@RequestBody OrderVo orderVo) {
//        return ResponseEntity.ok(this.iPosOrderService.insertOrder(orderVo));
//    }
    @PostMapping
    public ResponseEntity<PosOrder> addOrder() {
        System.out.println("已触发");
        return ResponseEntity.ok(this.iPosOrderService.insertOrder());
    }
}
